﻿@model WaiGaoQiaoWeb.Models.OutstockGroupSporadicVM
@{
    ViewBag.Title = "AddOutstockSporadic";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("dp")
    @Html.Js("datepicker")
    <script src="../../Scripts/datepicker-zh.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#LeanDt").datepicker({ dateFormat: 'yy-mm-dd' });
            $("form").makeValidationInline();
            $.post('@Url.Action("RtnGoodsName", "Test")', { "Id": $("#GoodsID").val() }, function (data) {
                $("#Con_GoodsInfoGoodsName").val(data);
                $("#Con_GoodsInfoId").val($("#GoodsID").val());
            });
            //保存
            $("#btnSave").click(function (event) {
                var vid = $("#Con_GoodsInfoId").val();
                var vcount = $("#LeanCount").val();
                var vsel = vid + ',' + vcount;
                $.ajax({
                    type: "POST",
                    url: '@Url.Action("OutStockYzh1", "OutstockSporadic")',
                    data: { sel: vsel },
                    dataType: "json",
                    success: function (msg) {
                        if (msg == -2) {
                            showLoadingMsg("库存不足", { left: 300, top: 2 }, true, 3000);
                            return false;
                        }
                        if(msg == -3) {
                            showLoadingMsg("领用数量必须为正整数", { left: 300, top: 2 }, true, 3000);
                            return false;
                        }
                        else {
                            $("#GoodsID").val($("#Con_GoodsInfoId").val());
                            $("#GoodsID1").val($("#Con_GoodsInfoGoodsName").val());
                            if (!$("#fmEdit").valid()) {
                                return false;
                            }
                            $('#fmEdit').ajaxSubmit(function (callback) {
                                if (callback) {
                                    refresh();
                                }
                            });
                        }
                    }
                });


            }); // end of btnSave
            //关闭
            $("#btnCancel").click(function (e) {
                if ($("#ID").val() != "0") {
                    CloseModelWindow(null, true);
                    return false;
                }
                if (parent) {
                    for (var i = 0; i < parent.document.frames.length; i++) {
                        if (parent.document.frames[i].document.getElementById("orderno")) {
                            parent.document.frames[i].document.getElementById("orderno").value = $("#OrderNo").val();
                        }
                    }
                    CloseModelWindow(null, true);
                }
            });
            var option = {
                height: 220,
                width: 740,
                url: '@Url.Action("AddGetOutstockSporadicList")',
                colModel: [
                    { display: '编号', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                    { display: '领用日期', name: 'LeanDt', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '零星物品ID', name: 'GoodsID', width: 50, sortable: false, hide: true, align: 'left' },
                    { display: '零星物品', name: 'GoodsID', width: 150, sortable: false, hide: false, align: 'left' },
			        { display: '领用食堂', name: 'LeanDept', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '领用数量', name: 'LeanCount', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '操作人', name: 'Operator_ID', width: 120, sortable: false, hide: true, align: 'left' },
                    { display: '记录日期', name: 'RecordDateTime', width: 120, sortable: false, hide: true, align: 'left' },
                    { display: '批号', name: 'OrderNo', width: 80, sortable: false, hide: true, align: 'left' }
				],
                singleselected: true,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 5,
                rpOptions: [10, 15],
                showcheckbox: true,
                rowbinddata: true,
                query: $("#OrderNo").val()
            };
            var grid = $("#OutstockTemp").flexigrid(option);
            $("#btnDel").click(function () {
                var items = $(grid).getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要删除的零星物品!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (!confirm("确定要删除零星物品吗？")) {
                    return false;
                }
                var rowcount = 0;
                for (var i = 0; i < items.length; i++) {
                    var id = items[i][0];
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("DeleteSporadic")',
                        data: { id: id },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data) {
                                $("#OutstockTemp").flexOptions(option).flexReload();
                            }
                        },
                        error: function () { }
                    });   // end of ajax                    
                }
            });
            function refresh() {
                showLoadingMsg("保存成功", { left: 200, top: 6 }, true, 3000);
                $("#OutstockTemp").flexOptions(option).flexReload();
            }
        });        
    </script>
}
@using (Html.BeginForm("SaveOutstockSporadic", "OutstockSporadic", FormMethod.Post, new { id = "fmEdit" }))
{
    @Html.ValidationSummary(true)
    <div class="mainpanel">
        @Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.Operator_ID)
        @Html.HiddenFor(model => model.RecordDateTime)
        @Html.HiddenFor(model => model.OrderNo)
        <table style="width: 100%;">
            <tr>
                <td style="text-align: right;">
                    @Html.LabelFor(model => model.LeanDt)
                </td>
                <td>
                    @Html.EditorFor(model => model.LeanDt)
                    @Html.ValidationMessageFor(model => model.LeanDt)
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    @Html.LabelFor(model => model.GoodsID)
                </td>
                <td>
                    @Html.Partial("RtnSpoGoodsStocksLXList", new Model.WaiGaoQiao.Con_GoodsInfo())
                    @Html.HiddenFor(model => model.GoodsID)
                    @Html.HiddenFor(model => model.GoodsID1)
                    @Html.ValidationMessageFor(model => model.GoodsID)
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    @Html.LabelFor(model => model.LeanCount)
                </td>
                <td>
                    @Html.EditorFor(model => model.LeanCount)
                    @Html.ValidationMessageFor(model => model.LeanCount)
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">
                    @Html.LabelFor(model => model.LeanDept)
                </td>
                <td>@Html.DropDownListFor(model => model.LeanDept,
                                   ViewData["canteen"] as SelectList,
                                   new { @style = "width:150px; height:22px; font-size:13px;" })
                    @*@Html.EditorFor(model => model.LeanDept)
                    @Html.ValidationMessageFor(model => model.LeanDept)*@
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td style="margin: 0 auto;">
                    <a id="btnSave" class="button" href="javascript:void(0);"><span>保 存</span></a> <a
                        id="btnDel" class="button" href="javascript:void(0);"><span>删 除</span></a> <a id="btnCancel"
                            class="button" href="javascript:void(0);"><span>关 闭</span></a>
                </td>
            </tr>
        </table>
        <div style="width: 740px; overflow-x: scroll;">
            <table id="OutstockTemp" style="display: none;">
            </table>
        </div>
    </div>
}
